package com.seadragon.app.ksr.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name="OFFICE", schema="STAGING")
public class Office {
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "OFFICEIDSEQ")
	@SequenceGenerator(name = "OFFICEIDSEQ", sequenceName = "STAGING.OFFICE_ID_SEQ", schema="STAGING")	
	private long id;

	@Column(name="PHONE_NUMBER")
	private String phoneNumber;

	@OneToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST}, orphanRemoval=true)
	@JoinColumn(name="ADDRESS_ID")
	private Address address;
	
	@ManyToOne
	@JoinColumn(name="BUSINESS_ID")
	private Business business;

	@Column(name="EMAIL_ADDRESS")
	private String emailAddress;

	@Column(name="DESCRIPTION", length = 2048)
	private String description;

	@Column(name="SPECIALTY")
	private String specialty;
		
	@Column(name="PRICE_RANGE")
	private int priceRange;
	
	@Column(name="RATING")
	private int rating;
	
	@Column(name="PRICE")
	private int price;
	
	@Column(name="REVIEW_COUNT")
	private int reviewCount;
	
	@ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
	@Fetch(value = FetchMode.SUBSELECT)
	@JoinTable(name = "STAGING.OFFICE_PICTURE", 
	joinColumns = { @JoinColumn(name = "OFFICE_ID", referencedColumnName = "ID") }, 
	inverseJoinColumns = { @JoinColumn(name = "PICTURE_ID", referencedColumnName = "ID") })
	private List<Picture> pictures;
	
	@OneToOne(orphanRemoval=true)
	@JoinColumn(name="PRIMARY_PICTURE_ID")
	private Picture primaryPicture;
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Business getBusiness() {
		return business;
	}

	public void setBusiness(Business business) {
		this.business = business;
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	public String getSpecialty() {
		return specialty;
	}

	public void setSpecialty(String specialty) {
		this.specialty = specialty;
	}

	public int getRating() {
		return rating;
	}

	public void setRating(int rating) {
		this.rating = rating;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getReviewCount() {
		return reviewCount;
	}

	public void setReviewCount(int reviewCount) {
		this.reviewCount = reviewCount;
	}
	
	public void increaseReviewCount(int count){
		this.reviewCount += count;
	}

	public int getPriceRange() {
		return priceRange;
	}

	public void setPriceRange(int priceRange) {
		this.priceRange = priceRange;
	}

	public List<Picture> getPictures() {
		return pictures;
	}

	public void setPictures(List<Picture> pictures) {
		this.pictures = pictures;
	}

	public Picture getPrimaryPicture() {
		return primaryPicture;
	}

	public void setPrimaryPicture(Picture primaryPicture) {
		this.primaryPicture = primaryPicture;
	}
}
